<template>
  <ele-modal
    :width="750"
    :visible="visible"
    :confirm-loading="loading"
    title="接收后状态无法返回，请谨慎操作"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    @ok="save"
  >
    <a-form
      :label-col="{ md: { span: 7 }, sm: { span: 4 }, xs: { span: 24 } }"
      :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }"
    >
      <a-row :gutter="24">
        <a-col :md="23" :sm="23" :xs="23">
          <a-form-item label="接收仓库" v-bind="validateInfos.warehouse_code">
            <a-select
              :options="options"
              allow-clear
              autocomplete="off"
              placeholder="请选择"
              v-model:value.string="form.warehouse_code"
              @change="optionsUpdate"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form, message } from 'ant-design-vue';
  import { emailReg, phoneReg, identityReg } from 'ele-admin-pro';
  import { get_warehouse_select } from '@/api/material/select';
  // 表格列配置
  const useForm = Form.useForm;

  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean,
    // 编辑edit/新建add
    actionStatus: String,
    // 编辑数据id
    Code: Object,
    detail: String,
    over: Function
  });

  const emit = defineEmits(['done', 'update:visible']);
  const options = ref([]);
  // 提交状态
  const loading = ref(false);
  const form = reactive({
    code: '',
    warehouse_code: null,
    receive_status: 1
  });
  // 表单验证规则
  const rules = reactive({
    warehouse_code: [
      {
        required: true,
        message: '请选择',
        type: 'string',
        trigger: 'change'
      }
    ]
  });
  onMounted(() => {
    form.code = props.Code.code;
    getSelect();
  });
  const { validate, validateInfos } = useForm(form, rules);
  //接收仓库
  const getSelect = (val) => {
    get_warehouse_select({
      page: 1,
      page_size: 9999
    })
      .then((res) => {
        options.value = res;
      })
      .catch((e) => {});
  };
  //切换
  const optionsUpdate = (val) => {
    form.warehouse_code = val;
  };
  /* 保存编辑 */
  const save = () => {
    if (props.detail && props.detail == 'detail') {
      //详情页引入时
      props.over(form);
    } else {
      //列表页引入时
      emit('done', form);
    }
    updateVisible(false);
  };
  /* 更新visible */
  const updateVisible = (value) => {
    emit('update:visible', value);
  };
</script>
<style scoped></style>
